/*
 *    Copyright (c) 2018-2025, infomng All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *
 * Redistributions of source code must retain the above copyright notice,
 * this list of conditions and the following disclaimer.
 * Redistributions in binary form must reproduce the above copyright
 * notice, this list of conditions and the following disclaimer in the
 * documentation and/or other materials provided with the distribution.
 * Neither the name of the pig4cloud.com developer nor the names of its
 * contributors may be used to endorse or promote products derived from
 * this software without specific prior written permission.
 * Author: infomng
 */

import request from "@/router/axios";

export function fetchList(query) {
  return request({
    url: "/admin-api/o3-workorder/workordercps/page",
    method: "get",
    params: query,
  });
}

export function addObj(obj) {
  return request({
    url: "/admin-api/o3-workorder/workordercps",
    method: "post",
    data: obj,
  });
}

export function getObj(id) {
  return request({
    url: "/admin-api/o3-workorder/workordercps/" + id,
    method: "get",
  });
}

export function delObj(id) {
  return request({
    url: "/admin-api/o3-workorder/workordercps/" + id,
    method: "delete",
  });
}

export function putObj(obj) {
  return request({
    url: "/admin-api/o3-workorder/workordercps",
    method: "put",
    data: obj,
  });
}

/**
 * 根据实际产线ID获取产线下的未完工工单集合
 * @param id
 * @returns {AxiosPromise}
 */
export function getWorkOrderListByLineId(id, moStatus) {
  return request({
    url:
      "/admin-api/o3-workorder/workordercps/getWorkOrderListByLineId/" +
      id +
      "/" +
      moStatus,
    method: "get",
  });
}

/**
 *工单排序
 * @param obj
 * @returns {AxiosPromise}
 */
export function workOrderSort(obj) {
  return request({
    url: "/admin-api/o3-workorder/workordercps/admin-api/o3-workorderSort",
    method: "post",
    data: obj,
  });
}

/**
 * 开始产线生产
 * @param obj
 * @returns {AxiosPromise}
 */
export function startLineProduction(lineId, lineStatus) {
  return request({
    url:
      "/admin-api/o3-workorder/workordercps/startLineProduction/" +
      lineId +
      "/" +
      lineStatus,
    method: "get",
  });
}

/**
 * 暂停产线生产
 * @param obj
 * @returns {AxiosPromise}
 */
export function pauseLineProduction(lineId, lineStatus) {
  return request({
    url:
      "/admin-api/o3-workorder/workordercps/pauseLineProduction/" +
      lineId +
      "/" +
      lineStatus,
    method: "get",
  });
}
/**
 * 继续产线生产
 * @param obj
 * @returns {AxiosPromise}
 */
export function continueLineProduction(lineId, lineStatus) {
  return request({
    url:
      "/admin-api/o3-workorder/workordercps/continueLineProduction/" +
      lineId +
      "/" +
      lineStatus,
    method: "get",
  });
}

/**
 *获取当前产线下的工单生产信息
 * @param obj
 * @returns {AxiosPromise}
 */
export function getWorkOrderProductionList(lineId, lineStatus) {
  return request({
    url:
      "/admin-api/o3-workorder/workordercps/getWorkOrderProductionList/" +
      lineId +
      "/" +
      lineStatus,
    method: "get",
  });
}

/**
 * 产线各工段报工
 * @param obj
 * @returns {*}
 */
export function saveWorkOrderReport(obj) {
  return request({
    url: "/admin-api/o3-workorder/workordercps/saveWorkOrderReport",
    method: "post",
    data: obj,
  });
}
/**
 *获取所有工单信息
 * @param obj
 * @returns {AxiosPromise}
 */
export function getAllWorkOrderInfo(lineId, lineStatus) {
  return request({
    url: "/admin-api/o3-workorder/workordercps/getWorkorderCpsList",
    method: "get",
  });
}

/**
 * 根据产线Id获取产线下可生产产品品号并根据品号去工单表查询可生产工单
 * @param obj
 * @returns {AxiosPromise}
 */
export function getDocNoByLineIdAndItemCode(lineId) {
  return request({
    url:
      "/admin-api/o3-workorder/workordercps/getDocNoByLineIdAndItemCode/" +
      lineId,
    method: "get",
  });
}

/**
 * 获取ERP工单品号集合
 * @returns {AxiosPromise}
 */
export function getItemCodeList() {
  return request({
    url: "/admin-api/o3-workorder/workordercps/getItemCodeList",
    method: "get",
  });
}

/**
 * 根据工单品号获取工单信息
 * @param {string} docNo
 */
export function getWorkOrderByDocNo(docNo) {
  return request({
    url:
      "/admin-api/o3-workorder/workordercps/getWorkOrderByDocNo?docNo=" + docNo,
    method: "get",
  });
}

/**
 * 根据工单品号获取工单信息
 * @param {string} docNo
 */
export function getDocNoListByType(type) {
  return request({
    url: "/admin-api/o3-workorder/workordercps/getDocNoListByType/" + type,
    method: "get",
  });
}

/**
 * 东衡4-3，获取订单号列表
 * @param {string} docNo
 */
export function getDocNo43List() {
  return request({
    url: "/admin-api/o3-workorder/opltshhs4-3/getDocNoList",
    method: "get",
  });
}

/**
 * 东衡2-3，获取订单号列表(干涉工单号)
 * @param {string} docNo
 */
export function getDocNo23GsList() {
  return request({
    url: "/admin-api/o3-workorder/interferometermtpro-dh/getDocNoList",
    method: "get",
  });
}

/**
 * 东衡2-3，获取订单号列表(极性工单号)
 * @param {string} docNo
 */
export function getDocNo23JxList() {
  return request({
    url: "/admin-api/o3-workorder/polarityproduction-dh/getDocNoList",
    method: "get",
  });
}

/**
 * 排查工单模糊查询
 * @param {string} docNo
 */
export function getDocNoList(docNo) {
  return request({
    url: "/admin-api/o3-workorder/workordercps/getDocNoList/" + docNo,
    method: "get",
  });
}

export function getDocNoDetail(id) {
  return request({
    url:
      "/admin-api/o3-workorder/workorderschedulemain/getSchedulePlanning/" + id,
    method: "get",
  });
}

export function saveSchedulePlanning(data) {
  return request({
    url: "/admin-api/o3-workorder/workorderschedulemain/saveSchedulePlanning",
    method: "post",
    data,
  });
}
